<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>右键点击提示</title>
  <style>
    /* 自定义右键菜单样式 */
    .custom-menu {
      display: none;
      position: absolute;
      background-color: #fff;
      border: 1px solid #ccc;
      box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
      z-index: 999;
    }
    .custom-menu li {
      padding: 8px 12px;
      cursor: pointer;
    }
    .custom-menu li:hover {
      background-color: #f0f0f0;
    }
  </style>
</head>
<body>
  <h1>右键点击页面</h1>

  <ul id="customMenu" class="custom-menu">
    <li onclick="alert('你点击了菜单项1')">菜单项 1</li>
    <li onclick="alert('你点击了菜单项2')">菜单项 2</li>
    <li onclick="alert('你点击了菜单项3')">菜单项 3</li>
  </ul>

  <script>
    // 获取自定义菜单
    const customMenu = document.getElementById('customMenu');

    // 监听右键点击事件
    document.addEventListener('contextmenu', function (event) {
      // 阻止默认的右键菜单
      event.preventDefault();

      // 显示自定义右键菜单
      customMenu.style.display = 'block';
      customMenu.style.left = `${event.pageX}px`;
      customMenu.style.top = `${event.pageY}px`;
    });

    // 监听点击事件，关闭右键菜单
    document.addEventListener('click', function () {
      customMenu.style.display = 'none';
    });
  </script>
</body>
</html>
